﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATest.Bll.Repositories;
using ATest.Bll;
using ATest.Bll.Errors;

namespace ATest.Tests.MockObjects
{
    public class MockTestRepository : Moq.Mock<ITestRepository>
    {
        public MockTestRepository()
        {
        }

        public MockTestRepository(Test test) : this()
        {
            SetTests(new []{test}.ToList());
        }

        public MockTestRepository(IEnumerable<Test> tests)
        {
            SetTests(tests);
        }

        public void SetTests(IEnumerable<Test> tests)
        {
            Setup(x => x.GetAll()).Returns(tests.AsQueryable());
            tests.ToList().ForEach(test => Setup(x => x.GetById(test.Id)).Returns(test));
        }

        public void SetSaveChangesThrowsValidationError()
        {
            Setup(x => x.SaveChanges()).Throws(new ValidationException());
        }
    }
}
